import * as RPCClient from '@alicloud/pop-core';
import { rpcclientInfo } from '../config';

const client = new RPCClient(rpcclientInfo)

const base64 = (msg: string) => {
    const b = new Buffer(msg);
    // console.log(b.toString('base64'))
    return b.toString('base64');
}

export const motormove = async ({ degreeX, degreeZ }) => {
    try {
        const res = await client.request('Pub', {
            ProductKey: `a1UQGzYoq9l`,
            TopicFullName: `/sys/a1UQGzYoq9l/RasbPi3/thing/service/motormove`,
            MessageContent: base64(JSON.stringify({
                params: {degreeX, degreeZ}
            }))
        })
        return res
    } catch (error) {
        return Promise.reject(error)
    }

}